<template>
  <page-header-wrapper :title="false">
    <a-card>
      <a-tabs type="card" @change="onTabs">
        <a-tab-pane v-for="item in tabOpts" :key="item.category_id">
          <span slot="tab">
            {{ item.category }}({{item.today_count}}/{{item.all_count}})
          </span>
        </a-tab-pane>
      </a-tabs>
      <Trademark :today="count.today" :total="count.total" v-if="activeKey == 10"></Trademark>
      <Patent :today="count.today" :total="count.total" v-if="activeKey == 20"></Patent>
      <Copyright :today="count.today" :total="count.total" v-if="activeKey == 30"></Copyright>
      <Design :today="count.today" :total="count.total" v-if="activeKey == 40"></Design>
      <International :today="count.today" :total="count.total" v-if="activeKey == 50"></International>
      <gao-xin :today="count.today" :total="count.total" v-if="activeKey == 60"></gao-xin>
      <ping-gu :today="count.today" :total="count.total" v-if="activeKey == 70"></ping-gu>
      <Iso :today="count.today" :total="count.total" v-if="activeKey == 80"></Iso>
      <gj-trademark :today="count.today" :total="count.total" v-if="activeKey == 90"></gj-trademark>
      <gj-patent :today="count.today" :total="count.total" v-if="activeKey == 100"></gj-patent>
      <three-a :today="count.today" :total="count.total" v-if="activeKey == 110"></three-a>
      <four-zero-zero :today="count.today" :total="count.total" v-if="activeKey == 120"></four-zero-zero>
      <Other :today="count.today" :total="count.total" v-if="activeKey == 300"></Other>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import { Trademark, Patent, Copyright, Design, International, PingGu, Other, Iso, GaoXin, GjTrademark, GjPatent, ThreeA, FourZeroZero } from './components'
  import { getCount } from '@/api/business'

  export default {
    name: 'BusinessList',
    components: {
      PingGu,
      Trademark,
      Patent,
      Copyright,
      Design,
      International,
      Other,
      Iso,
      GaoXin,
      GjTrademark,
      GjPatent,
      ThreeA,
      FourZeroZero
    },
    data () {
      return {
        tabOpts: {},
        activeKey: '10',
        count: {}
      }
    },
    created () {
      this.getCount()
    },
    methods: {
      onTabs (key) {
        const app = this
        app.count = {}
       for (const k in app.tabOpts) {
         if (key === app.tabOpts[k].category_id) {
           app.count['today'] = app.tabOpts[k].today_count
           app.count['total'] = app.tabOpts[k].all_count
         }
       }
       app.activeKey = key
      },
      getCount () {
        const app = this
        getCount().then(res => {
          if (res.status === 0) {
            app.tabOpts = res.result.category_count
            app.count['today'] = app.tabOpts[0].today_count
            app.count['total'] = app.tabOpts[0].all_count
          } else {
            app.$warning({
              title: res.msg
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
